
from django.shortcuts import render
from c2_guanliangliang.ana import ChipotleNan
# Create your views here.




REMOTE_HOST = "https://pyecharts.github.io/assets/js"
chipot = ChipotleNan()

def login(request):

    request.session['user_name'] = 'xx同学'
    return render(request, 'login.html')



def index_1(request):

    info_series = chipot.how_many_are_sold_per_item()

    bar = chipot.bar(axis0=info_series.index, axis1=info_series.values, name='每种商品卖的总数')

    context = {
        "myechart": bar.render_embed(),          #必须是myechart
        "host": REMOTE_HOST,
        "script_list": bar.get_js_dependencies()
    }

    return render(request, 'index.html', context)



def index_2(request):

    info = chipot.the_total_price_of_each_item()

    bar = chipot.bar(axis0=info.index, axis1=info.item_price, name='每种商品卖的总金额')

    context = {
        "myechart": bar.render_embed(),
        "host": REMOTE_HOST,
        "script_list": bar.get_js_dependencies()
    }

    return render(request, 'index.html', context)

def index_3(request):

    info = chipot.biao_three()

    bar = chipot.bar(axis0=info.index,axis1=info.item_price, name='超过10美元的商品')

    context = {
        "myechart": bar.render_embed(),
        "host": REMOTE_HOST,
        "script_list": bar.get_js_dependencies()
    }

    return render(request, 'index.html', context)


def index_4(request):
    info = chipot.biao_four()

    bar = chipot.bar(info.index, info.values, name="每种商品的单价")

    context = {
        "myechart": bar.render_embed(),
        "host": REMOTE_HOST,
        "script_list": bar.get_js_dependencies()
    }

    return render(request, "index.html", context)
